package com.guo.rpc.invoke;

import org.springframework.stereotype.Component;

import java.lang.reflect.InvocationTargetException;

/**
 * @Author: ljguo4
 * @email: ljguo4@iflytek.com
 * @Date: 2021/8/9 20:14
 * @Description:
 * @version: 1.0
 */
public class DefaultDispatcher implements Dispatcher{

    private volatile Invoker invoker;

    @Override
    public InvokeResult dispatch(Invocation invocation) throws InvocationTargetException, NoSuchMethodException, IllegalAccessException {
        if (invoker == null) {
            synchronized (this) {
                if (invoker == null) {
                    invoker = new ServerInvoker();
                }
            }
        }
        return invoker.invoke(invocation);
    }
}
